package com.zhp.utils;

import com.zhp.common.Constant;

public class PageUtil {

    /**
     * 根据总数量获取总分页数
     *
     * @param totalCount 总数量
     * @return 总分页数
     */
    public static long getTotalPage(long totalCount) {
        return totalCount % Constant.PAGE_SIZE == 0 ? totalCount / Constant.PAGE_SIZE : totalCount / Constant.PAGE_SIZE + 1;
    }


    /**
     * 获取当前页面的起始数
     *
     * @param currentPage 当前页
     * @return 起始页码
     */
    public static long getStratPage(long currentPage) {
        return currentPage % Constant.PAGE_COUNT == 0 ? currentPage - Constant.PAGE_COUNT + 1 : (currentPage - currentPage % Constant.PAGE_COUNT) +1 ;
//        return (currentPage - 1) * Constant.PAGE_SIZE + 1;
    }

    /**
     * 根据当前页获取末尾页码的位置
     *
     * @param currentPage 当前页
     * @param totalCount  总数
     * @return 末尾页码
     */
    public static long getEndPage(long currentPage, long totalCount) {
        long starPage = getStratPage(currentPage);
        long totalPage = getTotalPage(totalCount);
        long endPage = starPage + Constant.PAGE_COUNT - 1;
        return endPage > totalPage ? totalPage : endPage;

    }
}
